Skip to content

[Pages] Stub child_process.execSync directly in validation-helpers test - #133

Merged
Priyanshu Agrawal (priyanshu92) merged 1 commit into
mainfrom
users/priyanshuag/fix-validation-helpers-test-stub
Apr 29, 2026
Merged

[Pages] Stub child_process.execSync directly in validation-helpers test#133
Priyanshu Agrawal (priyanshu92) merged 1 commit into
mainfrom
users/priyanshuag/fix-validation-helpers-test-stub

Conversation

@priyanshu92

Copy link
Copy Markdown
Collaborator

Summary

Follow-up to #132 addressing copilot review feedback that arrived right around the time #132 was squash-merged (the fix commit landed on the branch but missed the merge).

The initial test in #132 stubbed child_process by swapping the entry in require.cache. Node treats built-in modules as native and the cache behavior for them is an implementation detail — works on current Node but not guaranteed across versions, and not the idiomatic node:test approach.

This PR switches to monkeypatching childProcess.execSync directly before requiring validation-helpers.js, with cleanup via t.after(). The helper is now exercised through its real require('child_process') call.

  • 1 file changed: plugins/power-pages/scripts/tests/validation-helpers.test.js (+18 / -26)
  • Test still passes (~30ms), no other behavior change.

Test plan

  • node --test plugins/power-pages/scripts/tests/validation-helpers.test.js passes
  • node --test plugins/power-pages/scripts/tests/ full suite stays green (141/141 locally)

🤖 Generated with Claude Code

Follow-up to #132. The initial test stubbed `child_process` by swapping
the entry in `require.cache`, which relies on Node's caching of built-in
modules — implementation detail that may not hold across versions.

Switch to monkeypatching `childProcess.execSync` directly before
requiring `validation-helpers.js`, with cleanup via `t.after()`. This
exercises the helper through its real `require('child_process')` call
and is the idiomatic node:test approach.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings April 29, 2026 11:49

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates the Power Pages Node test for getAuthToken to mock child_process.execSync in a more idiomatic and Node-version-stable way, avoiding reliance on require.cache behavior for built-in modules.

Changes:

  • Replace built-in module stubbing via require.cache with direct monkeypatching of child_process.execSync.
  • Ensure cleanup via t.after() and force a clean reload of validation-helpers.js around the patch.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@priyanshu92
Priyanshu Agrawal (priyanshu92) merged commit 48e49c4 into main Apr 29, 2026
9 checks passed
@priyanshu92
Priyanshu Agrawal (priyanshu92) deleted the users/priyanshuag/fix-validation-helpers-test-stub branch April 29, 2026 12:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants